#include <defines.h>

#ifndef _FD_H_
#define _FD_H_


//local da memoria reservado para o buffer do canal 2 de dma (do floppy)
#define MEM_FDC 0x80000
//registradores do FDC
#define REG_DOR 0x3f2
#define FDC_DSR 0x3f7
#define FDC_MSR 0x3f4
#define FDC_DATA 0x3f5
//estados, para agilizar o uso do disquete
#define EC 1
#define EF 3
#define EM 2
//comandos

#define CMD_SEEK 0xf
#define CMD_SPECIFY 0x3
#define CMD_INTSTATUS 0x8
#define CMD_RECALIBRATE 0x7
#define CMD_READ_DATA 0x6
#define CMD_READ_ID 0xa
#define CMD_WRITE_DATA 0x5

//bits auxiliares

#define BIT_MFM 0x40
#define BIT_MT 0x80

//Geometria
#define DG144_HEADS       2     /* heads per drive (1.44M) */
#define DG144_TRACKS     80     /* number of tracks (1.44M) */
#define DG144_SPT        18     /* sectors per track (1.44M) */
#define DG144_GAP3FMT  0x54     /* gap3 while formatting (1.44M) */
#define DG144_GAP3RW   0x1b     /* gap3 while reading/writing (1.44M) */

#define NO_RESET_FDC 4
#define HAB_INT_DMA 8

#define DSR_500K 0




//codigos de tratamento
#define SEMDISCO 1
#define DISCODEFEITO 2
#define FD_OK 0
#define FD_INITERROR 3





typedef struct DrvGeom {
   byte heads;
   byte tracks;
   byte spt;     /* setores por trilha */
} DrvGeom;


class fd
{
public:
	static void Installfd();
	static void fdTimer();
	static void fdISR();
	static void reset();
	static BOOL seek(int);
	static void motor(BOOL);
	static void block2hts(int block);
	static int IntStatus();
	static BOOL esperaInt(int);
	static BOOL recalibrate();
	static int read(int,char*);
	static int read(int,char*,int);
	static int write(int,char*);
	static int write(int,char*,int);
	static int inicia();
private:
	static int getbyte();
	static void sendbyte(int);
	static BOOL feito;
	static long int tmout;
	static DrvGeom geometry;
	static int cabeca,trilha,setor;
};

#endif